import {ajax,getMultiLang} from 'nc-lightapp-front';
import requestApi from '../requestApi'
import presetVar from '../presetVar';


export default function (props) {

    props.createUIDom(
        {
              pagecode: '201102HKD_card_001',//页面编码
             appcode: '201102HKD'//小应用编码
        },
        (data) => {
            getMultiLang({moduleId: 2011, domainName: 'erm',currentLocale: 'simpchn',callback: (json,status,inlt) => {
            this.multiLangJson = json;
            this.multiLangInlt = json;
            presetVar.pageCode.searchPage=props.getSearchParam("p");
            let metas = data.template;
            props.meta.setMeta(metas);
            let tempArr = [];
            let searchitem = metas[presetVar.areaCode.searchArea];
            let headmeta = metas[presetVar.areaCode.billsArea];
            let bodymeta = metas[presetVar.areaCode.bodysArea];

            searchitem.items.forEach((item) => {
                if(item.itemtype == 'refer'){
                    item.isShowUnit=true;
                }
               /* if(item.attrcode && item.attrcode=="pk_org" && window.defalutvalue.pk_org){
                    item.initialvalue = {value:window.defalutvalue.pk_org,display:window.defalutvalue.pk_org_value}
                }
                if(item.attrcode && item.attrcode=="pk_currtype" && window.defalutvalue.bzbm){
                    item.initialvalue = {value:window.defalutvalue.bzbm,display:window.defalutvalue.bzbm_value}
                }*/
                tempArr.push(item);
            });

            let PsndocTreeFilterPath ='nccloud.web.erm.action.ref.sqlbuilder.PsndocTreeGridRef';//人员
            let initquerycondition = {};
            //从后台获取当前登录用户关联人员所属的财务组织
            requestApi.getpageparam({
                data:{},
                success: (pk_org) => {
                    searchitem.items.forEach((item) => {
                        if (item.attrcode == 'jkbxr') {
                            item.queryCondition = ()=> {
                                //return {pk_org: pk_org[0]};
                                return {tradetype:'2647',pk_org:pk_org[0],org_id:pk_org[0],GridRefActionExt:PsndocTreeFilterPath,DataPowerOperationCode:'fi',/**使用权组**/isDataPowerEnable:'Y'};                
                            }
                        }
                    });
                    headmeta.items.forEach((item) => {
                        delete item.width;
                    });
                    bodymeta.items.forEach((item) => {
                        delete item.width;
                        if(item.attrcode == 'defitem50'){
                            if(this.dztz.amount && this.dztz.amount>0){
                                item.visible = true;
                            }else{
                                item.visible = false;
                            }
                        }
                        
                    });
                    let meta = {
                        ...metas,
                        searchArea: {
                            moduletype: 'search',
                            items : searchitem.items,
                            oid: searchitem.oid
                        },
                        head:{
                            moduletype: 'table',
                            items: headmeta.items
                        },
                        body:{
                            moduletype: 'table',
                            items: bodymeta.items
                        }
                    };
                    props.meta.setMeta(meta);
                    initquerycondition = props.search.getAllSearchData("20110ETLB");

                    if (Object.keys(initquerycondition).length != 0) {
                        //加载默认数据
                        let param={
                            querycondition:initquerycondition,
                            pagecode: '201102HKD_card_001',
                            dztz_amount:this.dztz.amount,
                            pageInfo:{
                                "pageIndex":-1,
                                "pageSize":10,
                                "totalPage":"0"
                            },
                            queryAreaCode:presetVar.areaCode.searchArea,  //查询区编码
                            oid:metas[presetVar.areaCode.searchArea].oid,  //查询模板id，手工添加在界面模板json中，放在查询区，后期会修改
                            querytype:'tree'
                        };
                        requestApi.query({
                            data:param,
                            success: (jkdata) => {
                                jkdata && props.transferTable.setTransferTableValue(presetVar.areaCode.billsArea, presetVar.areaCode.bodysArea, jkdata, 'pk_jkbx', 'pk_busitem');
                                let hasCache = props.transferTable.hasCache('ssc.erm.repayment.pull');
                                if(this.dztz.amount && this.dztz.amount>0){
                                    jkdata && this.setRowCheckedByDZTZ(jkdata);
                                }
                                console.log(566, hasCache)
                            }
                        })
                    }
                }
            });
        }})
        }
    );
}
